package com.linhh.mall.center.server.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linhh.mall.center.api.CollectionRecordService;
import com.linhh.mall.center.common.pojo.CollectionRecord;
import com.linhh.mall.center.server.mappers.CollectionRecordMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author linhh
 * @Date 2023 03 18 11 26
 **/
@Service
public class CollectionServiceRecordImpl implements CollectionRecordService {

    List<CollectionRecord> collectionRecordList = new ArrayList<>();

    @Autowired
    private CollectionRecordMapper collectionRecordMapper;

    /**
     *
     * @param lendTime  借出时间
     * @param returnTime  归还时间
     * @param target    借出目标
     * @param inKeeper  入库人
     * @param outKeeper  出库人
     * @return
     */
    @Override
    public List<CollectionRecord> getCollectionRecordList(String lendTime, String returnTime, String target, String inKeeper, String outKeeper) {
        // 根据筛选条件筛选借出3归还记录列表
        List<CollectionRecord> result = new ArrayList<>();
        for (CollectionRecord record: collectionRecordList){
            if((lendTime ==null || record.getLendTime().equals(lendTime))
                    && (returnTime == null || record.getReturnTime().equals(returnTime))
                    &&(target == null || record.getTarget().equals(target))
                    &&(inKeeper == null || record.getInKeeper().equals(inKeeper))
                    &&(outKeeper == null || record.getOutKeeper().equals(outKeeper))){
                result.add(record);
            }
        }
        return result;
    }

    /**
     * 增加藏品借出记录
     * @param record
     * @return
     */
    @Override
    public int addCollectionRecord(CollectionRecord record) {
        collectionRecordMapper.insertSelective(record);
        return 1;
    }


    /**
     * 分页查询实现
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<CollectionRecord> selectPageInfo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CollectionRecord> collectionRecords = collectionRecordMapper.selectAll();
        PageInfo<CollectionRecord> collectionPageInfo = new PageInfo<>(collectionRecords);
        return collectionPageInfo;
    }
}
